<?php

$services = [
    'user.login' => \App\Rpc\UserLoginServiceInterface::class,
];

return [
    'consumers' => value(function () use($services) {
        $consumers = [];
        foreach ($services as $name => $svc) {
            $consumer = [
                'name' => $name,
                'service' => $svc,
                'protocol'=> 'jsonrpc',
                'load_balancer' => 'random',
                'nodes' =>  [
                    ["host"=>"svcs","port"=>9501]
                ],
                'options' => [
                    'connect_timeout' => 5.0,
                    'recv_timeout' => 5.0,
                    'settings' => [
                        // 根据协议不同，区分配置
                        'open_eof_split' => true,
                        'package_eof' => "\r\n",
                    ],
                    // 重试次数，默认值为 2，收包超时不进行重试。暂只支持 JsonRpcPoolTransporter
                    'retry_count' => 2,
                    // 重试间隔，毫秒
                    'retry_interval' => 1000,
                    // 当使用 JsonRpcPoolTransporter 时会用到以下配置
                    'pool' => [
                        'min_connections' => 1,
                        'max_connections' => 2,
                        'connect_timeout' => 10.0,
                        'wait_timeout' => 3.0,
                        'heartbeat' => -1,
                        'max_idle_time' => 60.0,
                    ],
                ]
            ];
            //如果配置了consul就走服务发现，否则直接请求节点
            if(env('CONSUL_SERVER') != "")
            {
                $consumer['registry'] = [
                    'protocol' => 'consul', 'address' => env('CONSUL_SERVER','http://consul:8500'),
                ];
            }

            $consumers[] = $consumer;
        }
        return $consumers;
    }),
];